<template>
  <div>
    <el-form
      :model="form"
      class="box"
      label-width="auto"
      style="max-width: 600px"
    >
      <h1>登录页面</h1>
      <el-form-item label="用户名">
        <el-input v-model="form.userName" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.userPass" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { Login } from "@/api/api";
import { useRouter } from "vue-router";

const router = useRouter();

const form = ref({});
const onSubmit = () => {
  Login(form.value).then((res) => {
    console.log(res);
    if (res.data.code == 200) {
      window.sessionStorage.setItem("token", res.data.data);
      router.push("/home");
    }
  });
};
</script>

<style scoped></style>
